//
//  Tabltem.swift
//  Jock
//
//  Created by HD on 15/3/25.
//  Copyright (c) 2015年 Haidy. All rights reserved.
//

import UIKit

class TabItem: UIView {
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var titleView: UILabel!
    
    private var image: UIImage?
    private var selectedImage: UIImage?
    private var _select: Bool = false
    
    private var titleColor: UIColor = UIColor(red: 0x33 / 255, green: 0x33 / 255, blue: 0x33 / 255, alpha: 1)
    private var selectedTitleColor: UIColor = UIColor(red: 1, green: 0xa0 / 255, blue: 0x15 / 255, alpha: 1)
    
    // 设置Image
    func setImage(image: UIImage, selectedImage: UIImage) {
        self.image = image
        self.selectedImage = selectedImage
        select = _select
    }
    
}

extension TabItem {
    
    //选中
    var select: Bool {
        set {
            _select = newValue
            if _select {
                imageView.image = selectedImage
                titleView.textColor = selectedTitleColor
            } else {
                imageView.image = image
                titleView.textColor = titleColor
            }
        }
        
        get {
            return _select
        }
    }
    
    //标题
    var title: String {
        set {
            titleView.text = newValue
        }
        
        get {
            return titleView.text!
        }
    }
}
